package com.tensquare.qa.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.tensquare.qa.domain.Ul;
import com.tensquare.qa.service.IUlService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * ulController
 * 
 * @author hbxfwf
 * @date 2021-08-25
 */
@RestController
@RequestMapping("/ul")
public class UlController extends BaseController
{
    @Autowired
    private IUlService ulService;

    /**
     * 查询ul列表
     */
    @PreAuthorize(hasPermi = "qa:ul:list")
    @GetMapping("/list")
    public TableDataInfo list(Ul ul)
    {
        startPage();
        List<Ul> list = ulService.selectUlList(ul);
        return getDataTable(list);
    }

    /**
     * 导出ul列表
     */
    @PreAuthorize(hasPermi = "qa:ul:export")
    @Log(title = "ul", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Ul ul) throws IOException
    {
        List<Ul> list = ulService.selectUlList(ul);
        ExcelUtil<Ul> util = new ExcelUtil<Ul>(Ul.class);
        util.exportExcel(response, list, "ul数据");
    }

    /**
     * 获取ul详细信息
     */
    @PreAuthorize(hasPermi = "qa:ul:query")
    @GetMapping(value = "/{uid}")
    public AjaxResult getInfo(@PathVariable("uid") String uid)
    {
        return AjaxResult.success(ulService.selectUlByUid(uid));
    }

    /**
     * 新增ul
     */
    @PreAuthorize(hasPermi = "qa:ul:add")
    @Log(title = "ul", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Ul ul)
    {
        return toAjax(ulService.insertUl(ul));
    }

    /**
     * 修改ul
     */
    @PreAuthorize(hasPermi = "qa:ul:edit")
    @Log(title = "ul", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Ul ul)
    {
        return toAjax(ulService.updateUl(ul));
    }

    /**
     * 删除ul
     */
    @PreAuthorize(hasPermi = "qa:ul:remove")
    @Log(title = "ul", businessType = BusinessType.DELETE)
	@DeleteMapping("/{uids}")
    public AjaxResult remove(@PathVariable String[] uids)
    {
        return toAjax(ulService.deleteUlByUids(uids));
    }
}
